package cn.singno.bob.jpa.factory;

import java.io.Serializable;

import javax.persistence.EntityManager;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.repository.core.RepositoryMetadata;

import cn.singno.bob.jpa.base.impl.BaseRepositoryImpl;

public class RepositoryFactory extends JpaRepositoryFactory {   
	  
    public RepositoryFactory(EntityManager entityManager) {   
        super(entityManager);   
        // TODO Auto-generated constructor stub  
    }   
    @Override  
    @SuppressWarnings("unchecked")   
    protected <T, ID extends Serializable> JpaRepository<?, ?> getTargetRepository(RepositoryMetadata metadata, EntityManager em) {   
  
    	JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType());
    	//entityInformation.getJavaType();
      //  when(entityMetadata.getJavaType()).thenReturn((Class<Object>) metadata.getDomainType());   
        return new BaseRepositoryImpl(entityInformation, em);   
    }   
  
    /*  
     * (non-Javadoc)  
     *   
     * @see  
     * org.springframework.data.repository.support.RepositoryFactorySupport# 
     * getRepositoryBaseClass() 
     */  
    @Override  
    protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {   
        return BaseRepositoryImpl.class;   
    }   
}  
